package com.myway.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.internal.util.StringUtils;
import com.google.common.collect.Lists;
import com.myway.core.execption.IBEException;
import com.myway.core.util.HttpClientUtil;
import com.myway.dao.*;
import com.myway.dto.Result.*;
import com.myway.dto.Result.Flights;
import com.myway.dto.Result.Tickets;
import com.myway.dto.Result.resultparam.*;
import com.myway.dto.common.JsonData;
import com.myway.dto.domain.*;
import com.myway.dto.ibe_param.*;
import com.myway.dto.ibe_param.TaxPrice;
import com.myway.dto.ibe_param.TicketPrice;
import com.myway.dto.order.domain.OrderStatus;
import com.myway.dto.order.domain.SegmentStatus;
import com.myway.dto.util.BigDecimalUtils;
import com.myway.dto.util.DateUtils;
import com.myway.dto.util.OrderNumberGenerator;
import com.myway.dto.vo.FlyOrderVo;
import com.myway.dto.vo.FlyPassengeVo;
import com.myway.dto.vo.FlyPnrVo;
import com.myway.dto.vo.FlySegmentVo;
import com.myway.pojo.*;
import com.myway.pojo.FlyOrder;
import com.myway.pojo.FlyPassenge;
import com.myway.pojo.FlyTickets;
import com.myway.service.AVService;
import com.myway.service.ibe.command.ReservePNRCommand;
import com.myway.service.order.PNRManage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * Created by yufei on 2018/4/2.
 */
@Service
@Slf4j
public class AVServiceImpl implements AVService {


    @Autowired
    private FlyOrderMapper flyOrderMapper;

    @Autowired
    private FlyTicketsMapper flyTicketsMapper;

    @Autowired
    private FlyPassengeMapper flyPassengeMapper;

    @Autowired
    private flyRebookruleMapper flyRebookruleMappers;

    @Autowired
    private FlyPnrMapper flyPnrMapper;

    @Autowired
    private FlySegmentMapper flySegmentMapper;

    @Autowired
    private FlyPassengerSegmentMapper flyPassengerSegmentMapper;

    @Autowired
    private ReservePNRCommand reservePNRCommand;

    @Autowired
    private FlyFrequentPassengerMapper flyFrequentPassengerMapper;


/*    private  final  String economyCabin="WEYBHKLMNOQTVXUGSRPA";

    private  final  String businessCabin="CDJIZ";*/

    /**
     * 查询航班
     *
     * @param criteria
     * @return
     */
    @Override
    public GlobalResult searchFlight(FlightCriteria criteria) {
        List<SegmentParam> list = new ArrayList<SegmentParam>();
        //单乘
        SegmentParam param = new SegmentParam();
        //添加始发地
        ArrayList<Origin> origins = new ArrayList<Origin>();
        Origin origin = new Origin();
        origin.setName(criteria.getOrgCity());
        origins.add(origin);
        param.setOrigin(origins);
        //添加目的地
        ArrayList<Destination> destinations = new ArrayList<Destination>();
        Destination destination = new Destination();
        destination.setName(criteria.getDstCity());
        destinations.add(destination);
        param.setDestination(destinations);
        //出发时间
        param.setDepartureDate(DateUtils.getDateParam(criteria.getFlightDate()));
        Map<String, Integer> passengerCount = new HashMap<>();
        passengerCount.put("adult", criteria.getAdult());
        passengerCount.put("child", criteria.getChild());
        passengerCount.put("infant", criteria.getInfant());
        list.add(param);
        if (!StringUtils.isEmpty(criteria.getTravlType()) && criteria.getTravlType().equals("rt")) {
            SegmentParam param1 = new SegmentParam();
            //添加始发地
            ArrayList<Origin> origins1 = new ArrayList<Origin>();
            Origin origin1 = new Origin();
            origin1.setName(criteria.getDstCity());
            origins1.add(origin1);
            param1.setOrigin(origins1);
            //添加目的地
            ArrayList<Destination> destinations1 = new ArrayList<Destination>();
            Destination destination1 = new Destination();
            destination1.setName(criteria.getOrgCity());
            destinations1.add(destination1);
            param1.setDestination(destinations1);
            //出发时间
            param1.setDepartureDate(DateUtils.getDateParam(criteria.getArrDate()));
            list.add(param1);
        }

        SegmentAndPassengerParam spp = new SegmentAndPassengerParam(list, passengerCount);
        String json = HttpClientUtil.doPostJson("http://47.75.92.162:49001/searchone/ow", JSON.toJSONString(spp));
        //String json = HttpClientUtil.doPostJson("http://127.0.0.1:8081/searchone/ow", JSON.toJSONString(spp));
        //String json = HttpClientUtil.doPostJson("http://47.75.92.162:49000/searchone/price", JSON.toJSONString(criteria));
        //若为空，则返回，
        if (json.contains("no flight solutions")) {
            return null;
        }
        SearchResult result = JSON.parseObject(json, SearchResult.class);
       // log.info("返回的结果=====  " + JSON.toJSON(result));
        //航班信息
        ArrayList<Flights> flights = result.getFlights();
        //多服务等级搜索时返回，指定服务等级搜索时为空，包含运价，仓位，旅客信息
        ArrayList<MulticabinSolutions> multicabinSolutions = result.getMulticabinSolutions();

        //封装给前端页面返回数据的对象
        List<SPResult> spResultList = new ArrayList<SPResult>();
        //多航班
        GlobalResult globalResult = new GlobalResult();
        boolean flag = false;
        if (flights != null && flights.size() > 0 && multicabinSolutions.size() > 0) {
            for (int i = 0; i < flights.size(); i++) {
                //判断输入航班的起飞时间与返回的航班起飞时间是否相等
                if (DateUtils.getDate(criteria.getFlightDate()).equals(flights.get(i).getDepartureDate())) {
                    flights.get(i).setArrivalTimeD(DateUtils.getArrivalTime(flights.get(0).getArrivalTime()));
                    flights.get(i).setDepartureTimeD(DateUtils.getDepartTime(flights.get(0).getDepartureTime()));
                    flights.get(i).setDepartureDateD(DateUtils.getDepart(flights.get(0).getDepartureDate(), flights.get(0).getDepartureTime()));
                    flights.get(i).setArrivalDateD(DateUtils.getArriva(flights.get(0).getArrivalDate(), flights.get(0).getArrivalTime()));
                    flag = true;
                }
            }
            //log.info("返回的结果=====  " + JSON.toJSON(result));
            if (flag == false) {
                return null;
            }
            flyRebookrule rebookrule = new flyRebookrule();

            for (int a = 0; a < multicabinSolutions.size(); a++) {
                ArrayList<Tickets> tickets = multicabinSolutions.get(a).getTickets();
                for (int b = 0; b < tickets.size(); b++) {
                    //该ticket 用到的运价集合
                    ArrayList<Fares> fares = tickets.get(b).getFares();
                    //数组中的每一个元素cabinCombo 为服务等级/品牌组合结果，
                    // 如往返程，去程经济舱运价，回程公务舱运价为一个 cabinCombo
                    ArrayList<MulticabinCombos> multicabinCombos = tickets.get(b).getMulticabinCombos();
                    for (int c = 0; c < fares.size(); c++) {
                        SPResult spResult = new SPResult();

                        //运价对应的仓位等级
                        spResult.setCabinPrice(fares.get(c).getCabin().trim());
                        //是否可以变更
                        spResult.setChangeable(fares.get(c).isChangeable());
                        //是否可以退票
                        spResult.setRefundable(fares.get(c).isRefundable());
                        //是否可以升舱
                        spResult.setUpgradable(fares.get(c).isUpgradable());

                        com.myway.dto.Result.resultparam.Flights flights1 = fares.get(c).getFlights().get(0);
                        Passengers passengers1 = flights1.getPassengers();

                        // 舱位对应的服务等级(经济，商务)
                        spResult.setCabin(passengers1.getCabin().trim());
                        //座位数
                        spResult.setSeat(passengers1.getSeats());
                        //订座舱位
                        String[] str = new String[]{passengers1.getRbdInfos().get(0).getRbd().trim()};
                        spResult.setRdb(str);

                        ArrayList<Passengers> passengers = multicabinCombos.get(c).getPassengers();
//                        float amount = passengers.get(0).getPrice().getTotal().getAmount();
                        float amount = multicabinCombos.get(c).getTicketPrice().getAmount();
                        //总票价包含税费
                        spResult.setTicketPriceAmout(BigDecimalUtils.getFloatAmount(amount));
                        spResult.setTicketPriceCurrency(passengers.get(0).getPrice().getTotal().getCurrency());

                        rebookrule.setCabin(passengers1.getRbdInfos().get(0).getRbd().trim());
                        rebookrule.setOneway("1");
                        rebookrule.setFlyNumber("MJ" + flights.get(0).getFlightNumber());
                        flyRebookrule rebookrule1 = flyRebookruleMappers.selectRules(rebookrule);
                        if (rebookrule1 != null) {
                            spResult.setEnRules(rebookrule1.getEnRules());
                            spResult.setCnRules(rebookrule1.getCnRules());
                        } else {
                            spResult.setEnRules("No Rules");
                            spResult.setCnRules("无");
                        }
                        spResultList.add(spResult);
                    }

                }

            }
            //如果第一个运价大于第二个运价，则进行倒序
            if (spResultList.size() > 1) {
                if (spResultList.get(0).getTicketPriceAmout() > spResultList.get(1).getTicketPriceAmout()) {
                    Collections.reverse(spResultList);
                }
            }
            globalResult = GlobalResult.build(200, "success", spResultList, flights);
        } else {
            globalResult = GlobalResult.build(500, "error");
        }
        return globalResult;
    }

    @Override
    public GlobalResult searchRoundTripFlight(FlightCriteria criteria) {
        List<SegmentParam> list = new ArrayList<SegmentParam>();
        //单乘
        SegmentParam param = new SegmentParam();
        //添加始发地
        ArrayList<Origin> origins = new ArrayList<Origin>();
        Origin origin = new Origin();
        origin.setName(criteria.getOrgCity());
        origins.add(origin);
        param.setOrigin(origins);
        //添加目的地
        ArrayList<Destination> destinations = new ArrayList<Destination>();
        Destination destination = new Destination();
        destination.setName(criteria.getDstCity());
        destinations.add(destination);
        param.setDestination(destinations);
        //出发时间
        param.setDepartureDate(DateUtils.getDateParam(criteria.getFlightDate()));
        Map<String, Integer> passengerCount = new HashMap<>();
        passengerCount.put("adult", criteria.getAdult());
        passengerCount.put("child", criteria.getChild());
        passengerCount.put("infant", criteria.getInfant());
        list.add(param);

        if (criteria.getTravlType().equals("rt")) {
            SegmentParam param1 = new SegmentParam();
            //添加始发地
            ArrayList<Origin> origins1 = new ArrayList<Origin>();
            Origin origin1 = new Origin();
            origin1.setName(criteria.getDstCity());
            origins1.add(origin1);
            param1.setOrigin(origins1);
            //添加目的地
            ArrayList<Destination> destinations1 = new ArrayList<Destination>();
            Destination destination1 = new Destination();
            destination1.setName(criteria.getOrgCity());
            destinations1.add(destination1);
            param1.setDestination(destinations1);
            //出发时间
            param1.setDepartureDate(DateUtils.getDateParam(criteria.getArrDate()));
            list.add(param1);
        }
        SegmentAndPassengerParam spp = new SegmentAndPassengerParam(list, passengerCount);

        String json = HttpClientUtil.doPostJson("http://47.75.92.162:49001/searchone/ow", JSON.toJSONString(spp));
        //String json = HttpClientUtil.doPostJson("http://47.75.92.162:49000/searchone/price", JSON.toJSONString(criteria));

        //String json = FileUtils.ReadFile("D:/ibe_result.json");
        //若为空，则返回，
        if (json.contains("no flight solutions")) {
            return null;
        }
        SearchResult result = JSON.parseObject(json, SearchResult.class);


        //航班信息
        ArrayList<Flights> flights = result.getFlights();
        //多服务等级搜索时返回，指定服务等级搜索时为空，包含运价，仓位，旅客信息
        ArrayList<MulticabinSolutions> multicabinSolutions = result.getMulticabinSolutions();
        boolean flag = false;
        for (int i = 0; i < flights.size(); i++) {
            //判断输入航班的起飞时间与返回的航班起飞时间是否相等
            flights.get(i).setArrivalTimeD(DateUtils.getArrivalTime(flights.get(i).getArrivalTime()));
            flights.get(i).setDepartureTimeD(DateUtils.getDepartTime(flights.get(i).getDepartureTime()));
            flights.get(i).setDepartureDateD(DateUtils.getDepart(flights.get(i).getDepartureDate(), flights.get(i).getDepartureTime()));
            flights.get(i).setArrivalDateD(DateUtils.getArriva(flights.get(i).getArrivalDate(), flights.get(i).getArrivalTime()));
            flag = true;
        }
        log.info("返回的结果=====  " + JSON.toJSON(result));
        if (flag == false) {
            return null;
        }


        flyRebookrule rebookrule = new flyRebookrule();
        //封装给前端页面返回数据的对象
        List<SPResult> spResultList = new ArrayList<SPResult>();
        //多航班
        GlobalResult globalResult = new GlobalResult();

        for (int a = 0; a < multicabinSolutions.size(); a++) {
            ArrayList<Tickets> tickets = multicabinSolutions.get(a).getTickets();
            for (int b = 0; b < tickets.size(); b++) {
                //该ticket 用到的运价集合
                ArrayList<Fares> fares = tickets.get(b).getFares();
                //数组中的每一个元素cabinCombo 为服务等级/品牌组合结果，
                // 如往返程，去程经济舱运价，回程公务舱运价为一个 cabinCombo
                ArrayList<MulticabinCombos> multicabinCombos = tickets.get(b).getMulticabinCombos();
                Map<String, Object> map = new HashMap<String, Object>();

                for (int d = 0; d < multicabinCombos.size(); d++) {
                    ArrayList<Integer> fares1 = multicabinCombos.get(d).getFares();
                    SPResult spResult = new SPResult();
                    ArrayList<Passengers> passengers = multicabinCombos.get(d).getPassengers();
                    String[] str = new String[2];
                    String cabins = "";
                    for (int c = 0; c < fares.size(); c++) {
                      /*  //运价对应的仓位等级
                        spResult.setCabinPrice(fares.get(c).getCabin().trim());
                        //是否可以变更
                        spResult.setChangeable(fares.get(c).isChangeable());
                        //是否可以退票
                        spResult.setRefundable(fares.get(c).isRefundable());
                        //是否可以升舱
                        spResult.setUpgradable(fares.get(c).isUpgradable());*/

                        com.myway.dto.Result.resultparam.Flights flights1 = fares.get(c).getFlights().get(0);
                        Passengers passengers1 = flights1.getPassengers();
                        if (c % 2 == 0) {
                            com.myway.dto.Result.resultparam.Flights flights2 = fares.get(c + 1).getFlights().get(0);
                            Passengers passengers2 = flights2.getPassengers();
                            if (passengers1.getSeats() > passengers2.getSeats()) {
                                spResult.setSeat(passengers2.getSeats());
                            } else {
                                spResult.setSeat(passengers1.getSeats());
                            }
                        }
                        passengers1.getSeats();
                        //订座舱位
                        for (int e = 0; e < fares1.size(); e++) {
                            if (fares1.get(e).equals(fares.get(c).getId())) {
                                str[e] = passengers1.getRbdInfos().get(0).getRbd().trim();
                                cabins += passengers1.getCabin().trim() + ",";
                            }
                            // 舱位对应的服务等级(经济，商务)
                        }

                    }

                    if (!cabins.equals("")) {
                        spResult.setCabin(cabins.substring(0, cabins.length() - 1));
                    }
                    spResult.setRdb(str);
//                    if(str[0].equals(str[1])){
                    rebookrule.setCabin(str[0]);
                    rebookrule.setOneway("0");
                    rebookrule.setFlyNumber("MJ" + flights.get(0).getFlightNumber());
                    flyRebookrule rebookrule1 = flyRebookruleMappers.selectRules(rebookrule);
                    if (rebookrule1 != null) {
                        spResult.setEnRules(rebookrule1.getEnRules());
                        spResult.setCnRules(rebookrule1.getCnRules());
                    } else {
                        spResult.setEnRules("No Rules");
                        spResult.setCnRules("无");
                    }
//                    }

//                    float amount = passengers.get(0).getPrice().getTotal().getAmount();
                    float amount = multicabinCombos.get(d).getTicketPrice().getAmount();
                    //总票价包含税费
                    spResult.setTicketPriceAmout(BigDecimalUtils.getFloatAmount(amount));
                    spResult.setTicketPriceCurrency(passengers.get(0).getPrice().getTotal().getCurrency());
                    spResultList.add(spResult);
                }
            }
        }
        for (int i = spResultList.size() - 1; i >= 0; i--) {
            String cabin = spResultList.get(i).getCabin();
            if (!StringUtils.isEmpty(cabin)) {
                String[] split = cabin.split(",");
                if (!split[0].equals(split[1])) {
                    spResultList.remove(i);
                }
            }

        }
        //如果第一个运价大于第二个运价，则进行倒序
        if (spResultList.size() == 2)
            if (spResultList.get(0).getTicketPriceAmout() > spResultList.get(1).getTicketPriceAmout()) {
                Collections.reverse(spResultList);
            }
        globalResult = GlobalResult.build(200, "success", spResultList, flights);

        return globalResult;
    }

    /**
     * 查询日历票价方法
     *
     * @param criteria
     * @return
     */
    @Override
    public String searchCalenderFlight(FlightCriteria criteria) {
        criteria.setNewDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        List<SegmentParam> list = new ArrayList<SegmentParam>();
        SegmentParam param = new SegmentParam();
        //当前时间前几天
        int dayBefore = DateUtils.numDays(criteria.getFlightDate(), criteria.getNewDate());
        dayBefore = dayBefore >= 6 ? 6 : dayBefore;
        log.info("当前时间前几天=====" + dayBefore);
        //当前时间后几天
        int dayAfter = 8;
        FlexInterval flexInterval = new FlexInterval();
        flexInterval.setFrom(dayBefore);
        flexInterval.setTo(7);
        param.setFlexInterval(flexInterval);

        //添加始发地
        ArrayList<Origin> origins = new ArrayList<Origin>();
        Origin origin = new Origin();
        origin.setName(criteria.getOrgCity());
        origins.add(origin);
        param.setOrigin(origins);
        //添加目的地
        ArrayList<Destination> destinations = new ArrayList<Destination>();
        Destination destination = new Destination();
        destination.setName(criteria.getDstCity());
        destinations.add(destination);
        param.setDestination(destinations);
        //出发时间
        param.setDepartureDate(DateUtils.getDateParam(criteria.getFlightDate()));
        //乘客数量
        Map<String, Integer> passengerCount = new HashMap<>();
        passengerCount.put("adult", criteria.getAdult());
        passengerCount.put("child", criteria.getChild());
        passengerCount.put("infant", criteria.getInfant());
        list.add(param);

        SegmentAndPassengerParam spp = new SegmentAndPassengerParam(list, passengerCount);

        //String json = HttpClientUtil.doPostJson("http://47.75.92.162:49000/price/fare", JSON.toJSONString(list));

        //正式
        String json = HttpClientUtil.doPostJson("http://47.75.92.162:49001/searchone/calendar", JSON.toJSONString(spp));
        //测试
        // String json = HttpClientUtil.doPostJson("http://127.0.0.1:8081/searchone/calendar", JSON.toJSONString(spp));
        //若为空，则返回，


        SearchResult result = JSON.parseObject(json, SearchResult.class);
        String newDate = null;
        newDate = DateUtils.addjianDay(criteria.getFlightDate(), -dayBefore);

        ArrayList<Flights> flights = result.getFlights();
        ArrayList<Solutions> solutions = result.getSolutions();
        /*ArrayList<Flights> flights = new ArrayList<>();
        ArrayList<Solutions> solutions = new ArrayList<>();*/
        String substring = "";

        String[] calendarList = new String[dayBefore + 7];
        StringBuffer buff = new StringBuffer();
        String str = "";
        String[] split = new String[2];
        try {
            if (flights.size() > 0 && solutions.size() > 0) {
                for (int j = 0; j < dayBefore + 7; j++) {
                    for (int i = 0; i < flights.size(); i++) {
                        String dateStr = DateUtils.getDepartureDateStr(flights.get(i).getDepartureDate());
                        if (newDate.equals(dateStr)) {
                            DecimalFormat df = new DecimalFormat("#.00");
//                            BestPriceAcrossAgenciesBaseFare bf = solutions.get(i).getBestPriceAcrossAgenciesBaseFare();
                            BestPriceAcrossAgenciesTotal bf = solutions.get(i).getBestPriceAcrossAgenciesTotal();
                            calendarList[j] = newDate + "*" + df.format(bf.getAmount()) + " " + bf.getCurrency();
                            break;
                        } else {
                            calendarList[j] = newDate + "*--";
                        }

                    }

                    Date date = DateUtils.addOneDay(new SimpleDateFormat("yyyy-MM-dd").parse(newDate));
                    newDate = new SimpleDateFormat("yyyy-MM-dd").format(date);
                    continue;
                }
            } else {
                for (int j = 0; j < dayBefore + 7; j++) {
                    calendarList[j] = newDate + "*--";
                    Date date = DateUtils.addOneDay(new SimpleDateFormat("yyyy-MM-dd").parse(newDate));
                    newDate = new SimpleDateFormat("yyyy-MM-dd").format(date);
                }
                //log.info("substring======@@@=======" + JSON.toJSON(calendarList));
            }
            for (int c = 0; c < calendarList.length; c++) {
                split = calendarList[c].split("\\*");
                Date date = new SimpleDateFormat("yyyy-M-d").parse(split[0]);
                str = new SimpleDateFormat("yyyy-M-d").format(date);
                str = str + "*" + split[1];
                buff.append(str).append(",");
            }

            substring = buff.substring(0, buff.length() - 1);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return substring;
    }



    /**
     * 查询日历  一个月
     *
     * @param criteria
     * @return
     */
    @Override
    public String searchMonthCalenderPrice(FlightCriteria criteria) {
        criteria.setNewDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        List<SegmentParam> list = new ArrayList<SegmentParam>();
        SegmentParam param = new SegmentParam();
        //当前时间前几天
        int dayBefore = DateUtils.numDays(criteria.getFlightDate(), criteria.getNewDate());
        dayBefore = dayBefore >= 30 ? 30 : dayBefore;
        int dayafter=60-dayBefore;
        log.info("当前时间前几天=====" + dayBefore);
        //当前时间后几天
        int dayAfter = 8;
        FlexInterval flexInterval = new FlexInterval();
        flexInterval.setFrom(dayBefore);
        flexInterval.setTo(dayafter);
        param.setFlexInterval(flexInterval);

        //添加始发地
        ArrayList<Origin> origins = new ArrayList<Origin>();
        Origin origin = new Origin();
        origin.setName(criteria.getOrgCity());
        origins.add(origin);
        param.setOrigin(origins);
        //添加目的地
        ArrayList<Destination> destinations = new ArrayList<Destination>();
        Destination destination = new Destination();
        destination.setName(criteria.getDstCity());
        destinations.add(destination);
        param.setDestination(destinations);
        //出发时间
        param.setDepartureDate(DateUtils.getDateParam(criteria.getFlightDate()));
        //乘客数量
        Map<String, Integer> passengerCount = new HashMap<>();
        passengerCount.put("adult", criteria.getAdult());
        passengerCount.put("child", criteria.getChild());
        passengerCount.put("infant", criteria.getInfant());
        list.add(param);

        SegmentAndPassengerParam spp = new SegmentAndPassengerParam(list, passengerCount);
        //正式
        String json = HttpClientUtil.doPostJson("http://47.75.92.162:49001/searchone/calendar", JSON.toJSONString(spp));
        SearchResult result = JSON.parseObject(json, SearchResult.class);
        String newDate = null;
        newDate = DateUtils.addjianDay(criteria.getFlightDate(), -dayBefore);

        ArrayList<Flights> flights = result.getFlights();
        ArrayList<Solutions> solutions = result.getSolutions();

        String substring = "";
        String[] calendarList = new String[dayBefore + 30];
        StringBuffer buff = new StringBuffer();
        String str = "";
        String[] split = new String[2];
        try {
            if (flights.size() > 0 && solutions.size() > 0) {
                for (int j = 0; j < dayBefore + 30; j++) {
                    for (int i = 0; i < flights.size(); i++) {
                        String dateStr = DateUtils.getDepartureDateStr(flights.get(i).getDepartureDate());
                        if (newDate.equals(dateStr)) {
                            DecimalFormat df = new DecimalFormat("#.00");
                            BestPriceAcrossAgenciesTotal bf = solutions.get(i).getBestPriceAcrossAgenciesTotal();
                            calendarList[j] = newDate + "*" + df.format(bf.getAmount()) + " " + bf.getCurrency();
                            break;
                        } else {
                            calendarList[j] = newDate + "*--";
                        }

                    }

                    Date date = DateUtils.addOneDay(new SimpleDateFormat("yyyy-MM-dd").parse(newDate));
                    newDate = new SimpleDateFormat("yyyy-MM-dd").format(date);
                    continue;
                }
            } else {
                for (int j = 0; j < dayBefore + 30; j++) {
                    calendarList[j] = newDate + "*--";
                    Date date = DateUtils.addOneDay(new SimpleDateFormat("yyyy-MM-dd").parse(newDate));
                    newDate = new SimpleDateFormat("yyyy-MM-dd").format(date);
                }
               // log.info("substring======@@@=======" + JSON.toJSON(calendarList));
            }
            for (int c = 0; c < calendarList.length; c++) {
                split = calendarList[c].split("\\*");
                Date date = new SimpleDateFormat("yyyy-M-d").parse(split[0]);
                str = new SimpleDateFormat("yyyy-M-d").format(date);
                str = str + "*" + split[1];
                buff.append(str).append(",");
            }

            substring = buff.substring(0, buff.length() - 1);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return substring;
    }





    @Override
    @Transactional
    public GlobalResult addFlightOrder(FlyOrderVo flyOrderVo, TotalFlyPrice totalFlyPrice, List<TaxPrice> taxPrices, String userId, String flyPassengeVoListStr) {
        Boolean pnrIsCreate = false;
        if (flyOrderVo == null) {
            return GlobalResult.build(500, "info not entry");
        }
        List<FlySegmentVo> segmentsList = flyOrderVo.getSegments();
        if (segmentsList.size() == 0) {
            return GlobalResult.build(500, "flight info not entry");
        }
      /*  List<FlyPassengeVo> passengesList = flyOrderVo.getPassenges();
        if(passengesList.size()==0){
            return GlobalResult.build(500,"passenges info not entry");
        }*/
        if (flyPassengeVoListStr.isEmpty()) {
            return GlobalResult.build(500, "passenges info not entry");
        }

        if (flyOrderVo.getContactName() == null) {
            return GlobalResult.build(500, "ContactName info not entry");
        }
        if (flyOrderVo.getContactMoble() == null && flyOrderVo.getContactTel() == null) {
            return GlobalResult.build(500, "ContactMoble info not entry");
        }
        if (flyOrderVo.getContactName() == null) {
            return GlobalResult.build(500, "ContactName info not entry");
        }

        flyOrderVo.setUserId(userId);
        flyOrderVo.setOrderStatus(OrderStatus.WP.toString());
        flyOrderVo.setPnrImport("0");
        flyOrderVo.setIssurSmsSend("0");
        flyOrderVo.setUpdateDate(new Date());
        flyOrderVo.setCreator(userId);
        flyOrderVo.setAirlineCode("MJ");
        flyOrderVo.setInternational("1");
        List<FlyPassengeVo> flyPassengeVoList = JSONObject.parseArray(flyPassengeVoListStr, FlyPassengeVo.class);
        flyOrderVo.setPassenges(flyPassengeVoList);
        try {
            //IBE PNR
            PNRManage.getDefaultInstance().creatPNR(flyOrderVo, totalFlyPrice, taxPrices);
            pnrIsCreate = true;
        } catch (IBEException e) {
            pnrIsCreate = false;
            log.info("==========@@@====>>生成pnr失败============");
            e.printStackTrace();
            //return GlobalResult.build(500,"order add failure by IBE pnr");
        }

        /*Map<String,Object> params=new HashMap<String,Object>();
        params.put("order",flyOrderVo);
        params.put("segments",segmentsList);
        params.put("passenges",flyPassengeVoList);//旅客需要按成人、儿童分批预订
        params.put("totalFlyPrice",totalFlyPrice);
        params.put("taxPrices",taxPrices);
        params=reservePNRCommand.execute(params);//散客单批生成PNR*/

        //订单
        if (!pnrIsCreate) {
            flyOrderVo.setOrderStatus(OrderStatus.XX.toString());
        }
        int addflyOrderNum = flyOrderMapper.insertSelective(flyOrderVo);
        if (addflyOrderNum < 0) {
            log.info("==========@@@@=====》》》生成订单失败=====");
            return GlobalResult.build(500, "order add failure by order");
        }
        Long orderId = flyOrderVo.getId();
        //PNR
        // Find distinct PNR from passenger list
        Set<FlyPnrVo> pnrValueSet = getDistinctPnr(flyOrderVo);
        List<FlyPnrVo> persistedPnrList = persistPnr(pnrValueSet);
        //航段
        boolean segmentVoflag = true;
        for (int i = 0; i < segmentsList.size(); i++) {
            segmentsList.get(i).setOrderId(orderId);
            int addsegmentVoNum = flySegmentMapper.insertSelective(segmentsList.get(i));
            if (addsegmentVoNum < 0) {
                segmentVoflag = true;
                break;
            }
            segmentVoflag = false;
        }
        if (segmentVoflag) {
            log.info("==========@@@@=====》》》航段信息添加失败=====");
            return GlobalResult.build(500, "order add failure by segment");
        }
        //旅客
        boolean passengeVoflag = true;
        //旅客航段
        Boolean flyPassengerSegmentFlag = false;
        for (FlyPassengeVo passengeVo : flyOrderVo.getPassenges()) {
            FlyPassengeVo accompaniedBy = null;
            if (passengeVo.getPassageType().equals(PassengerType.CHILD)) {//添加儿童携带成人
                if (passengeVo.getAccompaniedByPassenger() != null) {
                    for (FlyPassengeVo ap : flyOrderVo.getPassenges()) {
                        if (ap.getPassageType().equals(PassengerType.ADULT)) {
                            if (passengeVo.getAccompaniedByPassenger().getName() != null && ap.getName().equals(passengeVo.getAccompaniedByPassenger().getName())) {
                                accompaniedBy = ap;//名称匹配，添加订单时
                                break;
                            } else if (passengeVo.getAccompaniedByPassenger().getId() != null && ap.getId().equals(passengeVo.getAccompaniedByPassenger().getId())) {
                                accompaniedBy = ap;//ID匹配，补购时
                                break;
                            }
                        }
                    }
                }
            }
            createPassenger(passengeVo, flyOrderVo, segmentsList, accompaniedBy, persistedPnrList, totalFlyPrice, taxPrices);
            passengeVoflag = false;
        }

        if (passengeVoflag) {
            return GlobalResult.build(500, "order add failure by passenger");
        }

        if (flyPassengerSegmentFlag) {
            return GlobalResult.build(500, "order add failure by passengerSegmeng");
        }

        if (!pnrIsCreate) {
            return GlobalResult.build(500, "order add failure by IBE pnr");
        }
        return GlobalResult.build(200, "order add success", orderId, "");
    }

    private void createPassenger(FlyPassengeVo passengeVo, FlyOrderVo order, List<FlySegmentVo> segmentsList, FlyPassengeVo accompaniedBy,
                                 List<FlyPnrVo> pnrList, TotalFlyPrice totalFlyPrice, List<TaxPrice> taxPrices) {
        passengeVo.setNumber(order.getId() + "");
        if (accompaniedBy != null) passengeVo.setAccompany(accompaniedBy.getId());
        findAndSetPnr(passengeVo, pnrList);//装载旅客pnr
        if (passengeVo.getPnr() != null) {
            passengeVo.setPnrId(passengeVo.getPnr().getId());
        }
        passengeVo.setIsFlightsms(0);
        passengeVo.setSetDate(new Date());
        passengeVo.setUpdateDate(new Date());
        passengeVo.setCateror(order.getUserId());
        passengeVo.setUserId(order.getUserId());
        if ((passengeVo.getId() != null && passengeVo.getId() != 0) || "on".equals(passengeVo.getCode())) {
            FlyFrequentPassenger flyFrequentPassenger1 = new FlyFrequentPassenger();
            // BeanUtils.copyProperties(passengeVo,flyFrequentPassenger1);
            FlyFrequentPassenger flyFrequentPassenger = getFlyFrequentPassenger(passengeVo);
            if (passengeVo.getId() != null && passengeVo.getId() != 0) {
                //修改常旅客
                flyFrequentPassengerMapper.updateByPrimaryKeySelective(flyFrequentPassenger);
            } else if (passengeVo.getCode().equals("on")) {
                flyFrequentPassengerMapper.insertSelective(flyFrequentPassenger);
            }
        }
        passengeVo.setId(null);
        int passengeVoNum = flyPassengeMapper.insertSelective(passengeVo);
        Collections.sort(segmentsList);//航段排序
        //旅客航段
        for (FlySegmentVo segmentVo : segmentsList) {
            FlyPassengerSegment flyPassengerSegment = new FlyPassengerSegment();
            flyPassengerSegment.setPassengerId(passengeVo.getId());
            flyPassengerSegment.setSegmentId(segmentVo.getId());
            flyPassengerSegment.setCurrency(segmentVo.getCurrency());
            flyPassengerSegment.setOrderId(order.getId());
            flyPassengerSegment.setMarketFare(new BigDecimal(totalFlyPrice.getAdultNotTaxAmount()));
            flyPassengerSegment.setNetFare(new BigDecimal(totalFlyPrice.getAdultAmount()));
            if (passengeVo.getPassageType().equals(PassengerType.CHILD)) {
                flyPassengerSegment.setMarketFare(new BigDecimal(totalFlyPrice.getChildrenNotTaxAmount()));
                flyPassengerSegment.setNetFare(new BigDecimal(totalFlyPrice.getChildrenAmount()));
            } else if (passengeVo.getPassageType().equals(PassengerType.INFANT)) {
                flyPassengerSegment.setMarketFare(new BigDecimal(totalFlyPrice.getBabayNotTaxAmount()));
                flyPassengerSegment.setNetFare(new BigDecimal(totalFlyPrice.getBabayAmount()));
            }
            double otherTax = 0.00;
            for (int i = 0; i < taxPrices.size(); i++) {
                TaxPrice taxPrice = taxPrices.get(i);
                if (taxPrice.getTaxCode() != null) {
                    if (taxPrice.getTaxCode().equals("CN")) {
                        flyPassengerSegment.setAirportTax(new BigDecimal(taxPrice.getAmount()));
                        continue;
                    }
                    if (taxPrice.getTaxCode().equals("YQ")) {
                        flyPassengerSegment.setFuelTax(new BigDecimal(taxPrice.getAmount()));
                        continue;
                    }
                }

                otherTax += taxPrice.getAmount();

                if (flyPassengerSegment.getTax1() == null) {
                    flyPassengerSegment.setAirportTax(new BigDecimal(taxPrice.getAmount()));
                    continue;
                }
                if (flyPassengerSegment.getTax2() == null) {
                    flyPassengerSegment.setAirportTax(new BigDecimal(taxPrice.getAmount()));
                    continue;
                }
                if (flyPassengerSegment.getTax3() == null) {
                    flyPassengerSegment.setAirportTax(new BigDecimal(taxPrice.getAmount()));
                    continue;
                }
                if (flyPassengerSegment.getTax4() == null) {
                    flyPassengerSegment.setAirportTax(new BigDecimal(taxPrice.getAmount()));
                    continue;
                }

            }
            flyPassengerSegment.setOtherTaxes(new BigDecimal(otherTax));
            flyPassengerSegment.setStatus("HK");
            int addflyPassengerSegmentNum = flyPassengerSegmentMapper.insertSelective(flyPassengerSegment);
        }

        // Process all accompanying passengers (i.e. infants) of current passenger
        if (!CollectionUtils.isEmpty(passengeVo.getAccompanyingPassengerList())) {
            for (FlyPassengeVo ap : passengeVo.getAccompanyingPassengerList()) {
                //携带者中只处理婴儿，儿童按成人保存，避免儿童保存重复
                if (ap.getPassageType().equals(PassengerType.INFANT))
                    createPassenger(ap, order, segmentsList, passengeVo, pnrList, totalFlyPrice, taxPrices);
            }
        }
    }

    private FlyFrequentPassenger getFlyFrequentPassenger(FlyPassengeVo passengeVo) {
        if (passengeVo == null) {
            return new FlyFrequentPassenger();
        }
        FlyFrequentPassenger frequentPassenger = new FlyFrequentPassenger();
        frequentPassenger.setId(passengeVo.getId());
        frequentPassenger.setUserId(passengeVo.getUserId());
        frequentPassenger.setCusromerIds(passengeVo.getCusromerIds());
        frequentPassenger.setPassageType(passengeVo.getPassageType());
        frequentPassenger.setMoblePhone(passengeVo.getMoblePhone());
        frequentPassenger.setName(passengeVo.getXingE() + "/" + passengeVo.getMingE());
        frequentPassenger.setCardType(passengeVo.getCardType());
        frequentPassenger.setCardNo(passengeVo.getCardNo());
        frequentPassenger.setIsFlightsms(0);//0是正常 1是删除
        frequentPassenger.setOrderBy(passengeVo.getOrderBy());
        frequentPassenger.setSetDate(new Date());
        frequentPassenger.setUpdateDate(new Date());
        frequentPassenger.setCateror(passengeVo.getCateror());
        frequentPassenger.setInsure(passengeVo.getInsure());
        frequentPassenger.setPassgeBirth(passengeVo.getPassgeBirth());
        frequentPassenger.setXingE(passengeVo.getXingE());
        frequentPassenger.setMingE(passengeVo.getMingE());
        frequentPassenger.setPassgeBirthDate(passengeVo.getPassgeBirthDate());
        frequentPassenger.setAccompany(String.valueOf(passengeVo.getAccompany()));
        return frequentPassenger;
    }

    private void findAndSetPnr(FlyPassengeVo dtoPax, List<FlyPnrVo> pnrList) {
        if (dtoPax.getPnr() != null) {
            for (FlyPnrVo pnr : pnrList) {
                if (pnr.getPnrNo().equals(dtoPax.getPnr().getPnrNo())) {
                    dtoPax.setPnr(pnr);
                    break;
                }
            }
        }
    }

    private Set<FlyPnrVo> getDistinctPnr(FlyOrderVo dtoOrder) {
        Set<FlyPnrVo> pnrValueSet = new HashSet<FlyPnrVo>();
        List<FlyPassengeVo> paxList = dtoOrder.getPassenges();
        for (FlyPassengeVo dtoPax : paxList) {
            if (!dtoPax.getPassageType().equals(PassengerType.INFANT.toString()) && dtoPax.getPnr() != null) {
                if (dtoPax.getPnr().equals(" ")) {
//                    Long pnrid=pnrDao.findPnrIdByPnrNo(dtoPax.getPnr().getPnrNo());
//                    dtoPax.getPnrValue().setId(pnrid);
                }
                if (!pnrValueSet.contains(dtoPax.getPnr())) pnrValueSet.add(dtoPax.getPnr());
            }
        }
        log.debug("Number of PNR in the order: " + pnrValueSet.size());
        return pnrValueSet;
    }

    /**
     * @param pnrValueSet
     * @return Persisted list of PNR
     */
    private List<FlyPnrVo> persistPnr(Set<FlyPnrVo> pnrValueSet) {
        List<FlyPnrVo> persistedPnrList = new ArrayList<FlyPnrVo>();
        for (FlyPnrVo pnrValue : pnrValueSet) {
            flyPnrMapper.insertSelective(pnrValue);
            persistedPnrList.add(pnrValue);
        }
        return persistedPnrList;
    }


    public List<FlySegmentVo> setMeals(List<FlySegmentVo> flySegmentVoList) {
        if (flySegmentVoList == null || flySegmentVoList.size() == 0) {
            return flySegmentVoList;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (FlySegmentVo flySegment : flySegmentVoList) {
            FlightParam flightParam = new FlightParam();
            flightParam.setFlightNo(flySegment.getFlightNo());
            flightParam.setFlightDate(sdf.format(flySegment.getDepTime()));
            String meal = com.myway.core.util.HttpClientUtil.doPostJson("http://47.75.92.162:49001/av/getMealList", JSON.toJSONString(flightParam));
            System.out.println("mealList==" + meal);
            flySegment.setMeals(meal);
        }
        return flySegmentVoList;
    }


    /**
     * 查询票价
     * @param criteria
     * @return
     */

   /* @Override
    public List<TicketPrice> searchPrice(FlightCriteria criteria) {
        List<TicketPrice> list=null;
        try{
            String priceList = HttpClientUtil.doPostJson("http://47.75.92.162:49000/price/fare", JSON.toJSONString(criteria));

            //String priceList = HttpClientUtil.doPostJson("http://172.17.19.23:8030/price/fare", JSON.toJSONString(criteria));
            String  priceList1 ="[{\"equivFareAmount\":1035.0,\"equivFareCurrentyCode\":\"GEL\",\"totalFareAmount\":1106.2,\"baseFareAmount\":350.0," +
                    "\"baseFareCurrencyCode\":\"EUR\",\"totalFareCurrencyCode\":\"GEL\",\"baseFareRate\":2.957,\"cabinType\":\"1\",\"" +
                    "taxPrices\":[{\"amount\":60.2,\"countryCode\":\"GE\",\"taxCode\":\"GE\",\"currencyCode\":\"GEL\",\"eXEMPT\":false,\"taxName\":\"passenger fee\"},{\"amount\":11.0,\"countryCode\":\"GE\",\"taxCode\":\"JA\",\"currencyCode\":\"GEL\",\"eXEMPT\":false,\"taxName\":\"airport passenger security fee\"}]},{\"" +
                    "equivFareAmount\":207.0,\"equivFareCurrentyCode\":\"GEL\",\"totalFareAmount\":278.2,\"baseFareAmount\":70.0,\"baseFareCurrencyCode\":\"EUR\",\"totalFareCurrencyCode\":\"GEL\",\"baseFareRate\":2.957,\"cabinType\":\"0\",\"" +
                    "taxPrices\":[{\"amount\":60.2,\"countryCode\":\"GE\",\"taxCode\":\"GE\",\"currencyCode\":\"GEL\",\"eXEMPT\":false,\"taxName\":\"passenger fee\"},{\"amount\":11.0,\"countryCode\":\"GE\",\"taxCode\":\"JA\",\"currencyCode\":\"GEL\",\"eXEMPT\":false,\"taxName\":\"airport passenger security fee\"}]}]";

             list = JSON.parseArray(priceList,TicketPrice.class);
        }catch(Exception e){
            e.printStackTrace();
        }
        return list;
    } */


    /**
     * 预定机票
     *
     * @param param
     * @param passgaeData
     * @param flyOrder
     * @return
     */
    @Override
    public JsonData searchFlyOrder(FlightParam param, String passgaeData, FlyOrder flyOrder, TicketPrice ticketPrice) {
        //将乘客字符串转成list对象
        List<FlyPassenge> passgaeList = JSONObject.parseArray(passgaeData, FlyPassenge.class);

        //构建航段类
        List<Segment> segments = Lists.newArrayList();
        Segment segment = new Segment();
        segment.setFlightNo(param.getFlightNo());
        segment.setOrgCity(param.getOrgCity());
        segment.setDstCity(param.getDstCity());

        Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(param.getFlightDate(), new ParsePosition(0));
        segment.setDepartDate(parse);

        List<Cabin> cabins = Lists.newArrayList();
        Cabin cb = new Cabin();
        cb.setCabinName(param.getCabinCode());
        cabins.add(cb);
        segment.setCabins(cabins);
        segments.add(segment);

        PnrVo pnrVo = new PnrVo();
        pnrVo.setFlyOrder(flyOrder);
        pnrVo.setPassenges(passgaeList);
        pnrVo.setSegments(segments);
        pnrVo.setTicketPrice(ticketPrice);

        Map map = saveFlyOrder(pnrVo);
        return JsonData.success(map);
    }

    /**
     * 将组装好的数据调用接口，查询pnr.
     *
     * @param pnrVo
     */
    public Map saveFlyOrder(PnrVo pnrVo) {
        Map map = new HashMap();
        String orderId = OrderNumberGenerator.getOrderNo() + "";
        List<FlyPassenge> passenges = pnrVo.getPassenges();
        List<Segment> segments = pnrVo.getSegments();
        TicketPrice ticketPrice = pnrVo.getTicketPrice();
        FlyOrder flyOrder = pnrVo.getFlyOrder();

        //将乘客信息插入数据库
        Iterator<FlyPassenge> iterator = passenges.iterator();
        while (iterator.hasNext()) {
            FlyPassenge next = iterator.next();
            //主键
//            next.setId(OrderNumberGenerator.getOrderNo()+"");
            //订单ID
            next.setNumber(orderId);
            next.setUserId(flyOrder.getUserId());
            //设置创建时间
            next.setSetDate(new Date());

            flyPassengeMapper.insertSelective(next);
        }

        //插入订单信息表
        //主键
//        flyOrder.setId(OrderNumberGenerator.getOrderNo()+"");
        //订单ID
        flyOrder.setOrderId(orderId);

        //订单状态
        flyOrder.setOrderStatus("未付款");

        flyOrder.setOrderCurrenry(flyOrder.getCurrency());

        flyOrder.setSetDate(new Date());
        flyOrder.setUpdateDate(new Date());
        long time = 30 * 60 * 1000;
        //限制时间
        flyOrder.setTimeLimit(new Date(new Date().getTime() + time));
        //航班编号
        flyOrder.setAirlineCode(segments.get(0).getFlightNo());
        flyOrderMapper.insertSelective(flyOrder);


        //机票相关数据
        FlyTickets flyTickets = new FlyTickets();
        //主键
        flyTickets.setId(OrderNumberGenerator.getOrderNo() + "");
        ////订单ID
        flyTickets.setOrderId(orderId);
        //机场客运费
        flyTickets.setTax1(ticketPrice.getTaxPrices().get(0).getAmount());
        //机场安全费
        flyTickets.setTax2(ticketPrice.getTaxPrices().get(1).getAmount());
        //客票编号
        // flyTickets.setTicketId(result.getTicketNo());
        //flightNo,航段ID
        flyTickets.setSegmentId(segments.get(0).getFlightNo());

        //单人总票价===现基础票价+税费（机场客运费，机场安全费）
        flyTickets.setMarketFare(ticketPrice.getTotalFareAmount());

        //原票价----对应TicketPrice的现基础票价
        flyTickets.setNewFare(ticketPrice.getEquivFareAmount());
        //------------------------现基础货币代码
        flyTickets.setCurrency(ticketPrice.getBaseFareCurrencyCode());
        //出发地
        flyTickets.setOrgCity(segments.get(0).getOrgCity());
        //目的地
        flyTickets.setDestCity(segments.get(0).getDstCity());

        flyTickets.setSetDate(new Date());
        flyTicketsMapper.insertSelective(flyTickets);


        //调用ibe接口，返回pnr
        //String sagementList = HttpClientUtil.doPostJson("http://172.17.19.23:8030/pnr/seat", JSON.toJSONString(pnrVo));
        // TicketResult  result = (TicketResult)JSONObject.parse(sagementList);
        TicketResult result = new TicketResult();
        result.setMsg("5555555");
        result.setResult("success");
        result.setPnrNo("123456789");
        result.setTicketNo("123456789");
        if (result.getResult().equals("success")) {
            while (iterator.hasNext()) {
                FlyPassenge next = iterator.next();
                //订单ID
                next.setNumber(orderId);
                //获取pnr编码
//                next.setPnrId(result.getPnrNo());
                next.setUpdateDate(new Date());
                flyPassengeMapper.updateByPrimaryKeySelective(next);
            }

            FlyTickets flyTicketsResult = new FlyTickets();
            //定单ID
            flyTicketsResult.setOrderId(orderId);
            //pnr号
            flyTicketsResult.setTicketId(result.getTicketNo());
            flyTicketsResult.setUpdateDate(new Date());
            flyTicketsMapper.updateByPrimaryKeySelective(flyTicketsResult);

        }

        map.put("result", result);
        map.put("orderId", orderId);
        map.put("totalPrice", flyOrder.getTotalPrice());
        return map;

    }

}
